<?php
/*
 * @Description    : 返回结果
 * @Version        : 1.0.0
 * @Author         : QianLong
 * @Date           : 2021-04-08 13:06:53
 * @LastEditors    : QianLong
 * @LastEditTime   : 2024-04-23 14:19:41
 */

namespace app\lib;

class Result
{
    //success
    static public function Success($data=[],$msg='success')
    {
        if (!empty($data)) {
            if (isset($data['data']) && !empty($data['data'])) {
                if (isset($data['data'][0]) && !empty($data['data'][0])) {
                    foreach ($data['data'] as $key => $vo) {
                        unset($data['data'][$key]['uid'],$data['data'][$key]['username']);
                    }
                }else{
                    unset($data['data']['uid']);
                }
            }else{
                if (isset($data['uid'])) {
                    unset($data['uid']);
                }
            }
        }
        $rs = [
            'code' => 200,
            'msg' => $msg,
            'data' => $data,
        ];
        return json($rs);
    }
    static public function AdminSuccess($data=[],$msg='success')
    {
        $rs = [
            'code' => 200,
            'msg' => $msg,
            'data' => $data,
        ];
        return json($rs);
    }
    //error
    static public function Error($msg, $code = -1)
    {
        $rs = [
            'code' => $code,
            'msg' => $msg,
            'data' => '',
        ];
        return json($rs);
    }
}
